﻿using System;

namespace Library.OrmEnterpriseEntity.TableInfo {
	/// <summary>
	/// 
	/// </summary>
	public abstract class DbTableView : ITableView {
		internal static DbTableView NullTableView = new NullDbTableView();
		///<summary>
		/// Create DbTable instance
		///</summary>
		///<returns></returns>
		public abstract DbTable CreateInstance();
		#region Implementation of ITableView

		public virtual string TableName {
			get { return GetType().Name; }
		}



		private ColumnViewCollection _columns;
		///<summary>
		///</summary>
		public virtual ColumnViewCollection Columns {
			get {
				if (_columns == null) {
					_columns = new ColumnViewCollection();
				}

				return _columns;
			}
		}

		#endregion

		private class NullDbTableView : DbTableView {

			public override ColumnViewCollection Columns {
				get {
					if (_columns == null) _columns = new Collection();
					return _columns;
				}
			}
			public override DbTable CreateInstance() {
				throw new NotImplementedException();
			}

			public override string TableName {
				get { return "Null table"; }
			}

			private class Collection : ColumnViewCollection {
				public override void Add(DbColumnView item) {

				}
				public override void Clear() {

				}
				public override bool Contains(DbColumnView item) {
					return false;
				}
				public override void CopyTo(DbColumnView[] array, int arrayIndex) {

				}
				public override int Count {
					get { return 0; }
				}
				public override bool Equals(object obj) {
					return this == obj;
				}
				public override int GetHashCode() {
					return 0;
				}
				public override int IndexOf(DbColumnView item) {
					return -1;
				}
				public override void Insert(int index, DbColumnView item) {

				}
				public override bool IsReadOnly {
					get { return true; }
				}
				public override bool Remove(DbColumnView item) {
					return false;
				}
				public override void RemoveAt(int index) {

				}
				public override DbColumnView this[int index] {
					get { return null; }
					set {

					}
				}

			}
		}
	}
}
